package com.yanqu.road.server.cmd.systemgroup.newmonopolymkt;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.newmonopolymkt.NewMonopolyMarketProto;
import com.yanqu.road.server.cmd.CrossAppointCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.systemgroup.newmonopolymkt.CrossNewMonopolyMarketGroup;
import com.yanqu.road.server.manager.systemgroup.newmonopolymkt.CrossNewMonopolyMarketMgr;
import com.yanqu.road.server.manger.NewMonopolyMarketCommonMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.utils.date.DateHelper;

@Cmd(code = Protocol.C_NEW_MONOPOLY_MARKET_GET_RANK_REWARD, desc = "领取榜单奖励")
public class CrossNewMonopolyMarketGetRankRewardCmd extends CrossAppointCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

        //领奖期间
        CrossNewMonopolyMarketGroup monopolyMarket = CrossNewMonopolyMarketMgr.getMarket(groupId);
        if(monopolyMarket != null) {

            if(!NewMonopolyMarketCommonMgr.inWeekRewardTime(monopolyMarket.getWeekStateData().getOfficeRefreshTime(), DateHelper.getCurrentSecond())){
                MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_NEW_MONOPOLY_MARKET_GET_RANK_REWARD,
                        NewMonopolyMarketProto.NewMonopolyMarketGetRankRewardRespMsg.newBuilder().setRet(GameErrorCode.E_NEW_MONOPOLY_MARKET_NOT_IN_REWARD_TIME)));
                return;
            }

            NewMonopolyMarketProto.NewMonopolyMarketGetRankRewardReqMsg msg = NewMonopolyMarketProto.NewMonopolyMarketGetRankRewardReqMsg.parseFrom(packet.getBytes());

            NewMonopolyMarketProto.NewMonopolyMarketGetRankRewardRespMsg.Builder builder = monopolyMarket.getUserRankReward(serverId, packet.getPlayerId(), msg.getType());
            if(builder.getRet() == 0){
                MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.S_NEW_MONOPOLY_MARKET_GET_RANK_REWARD_FROM_CROSS, builder));
            } else {
                MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_NEW_MONOPOLY_MARKET_GET_RANK_REWARD, builder));
            }
        }
    }

    @Override
    public void sendData() {

    }
}
